/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:54 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Chungchi_HocvienDAL : SqlProvider<Chungchi_HocvienEntity>
    {
        static Chungchi_HocvienDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Chungchi_HocvienEntity entity = new Chungchi_HocvienEntity();
				entity.PK_iChungchi_HocvienID = Int64.Parse("0"+dr["PK_iChungchi_HocvienID"].ToString());
				entity.FK_iChungchiID = Int16.Parse("0"+dr["FK_iChungchiID"].ToString());
				entity.FK_iHocvienID = Int64.Parse("0"+dr["FK_iHocvienID"].ToString());
				entity.sSochungchi = dr["sSochungchi"].ToString();
				entity.dNgaycap =String.IsNullOrEmpty(dr["dNgaycap"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaycap"].ToString());
				entity.iTrangthai = Int16.Parse("0"+dr["iTrangthai"].ToString());
                return entity;
            };
        }
        public static Chungchi_HocvienEntity GetOne(Int64 PK_iChungchi_HocvienID)
        {
            string cmdName = "spChungchi_Hocvien_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iChungchi_HocvienID", PK_iChungchi_HocvienID);
            Chungchi_HocvienEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Chungchi_HocvienEntity> GetAll()
        {
            string cmdName = "spChungchi_Hocvien_Get";
            return GetList(cmdName);
        }
        public static List<Chungchi_HocvienEntity> GetByFK_iChungchiID(Int16 FK_iChungchiID)
		{
			string cmdName = "spChungchi_Hocvien_GetByFK_FK_iChungchiID";
			SqlParameter p = new SqlParameter("@FK_iChungchiID",FK_iChungchiID);
			List<Chungchi_HocvienEntity> list = GetList(cmdName, p);
			return list;
		}public static List<Chungchi_HocvienEntity> GetByFK_iHocvienID(Int64 FK_iHocvienID)
		{
			string cmdName = "spChungchi_Hocvien_GetByFK_FK_iHocvienID";
			SqlParameter p = new SqlParameter("@FK_iHocvienID",FK_iHocvienID);
			List<Chungchi_HocvienEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(Chungchi_HocvienEntity entity)
        {
            string cmdName = "spChungchi_Hocvien_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Chungchi_HocvienEntity entity)
        {
            string cmdName = "spChungchi_Hocvien_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iChungchi_HocvienID)
        {
            string cmdName = "spChungchi_Hocvien_Delete";
            SqlParameter p = new SqlParameter("@PK_iChungchi_HocvienID", PK_iChungchi_HocvienID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Chungchi_HocvienEntity entity)
        {
            SqlParameter[] p = new SqlParameter[6];
			p[0] = new SqlParameter("@PK_iChungchi_HocvienID", entity.PK_iChungchi_HocvienID);
			p[1] = new SqlParameter("@FK_iChungchiID", entity.FK_iChungchiID);
			p[2] = new SqlParameter("@FK_iHocvienID", entity.FK_iHocvienID);
			p[3] = new SqlParameter("@sSochungchi", entity.sSochungchi);
			p[4] = new SqlParameter("@dNgaycap", entity.dNgaycap);
			p[5] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            return p;
        }
        #endregion
       
    }
}